<template>
  <j-modal
    :title="title"
    :width="800"
    :visible="visible"
    :confirmLoading="confirmLoading"
    switchFullscreen
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭"
  >
    <a-spin :spinning="confirmLoading">
      <a-form-model ref="form" :model="model" :rules="validatorRules">
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="deductMoney" label="申请提现金额">
          <div>
            <span></span><span>{{ amount }}</span>
          </div>
        </a-form-model-item>
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="deductMoney" label="扣费金额">
          <a-input-number
            style="width: 180px"
            placeholder="请输入扣费金额"
            v-model="model.deductMoney"
            :min="0"
            :max="amount"
          />
        </a-form-model-item>
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="deductExplains" label="扣费说明">
          <a-textarea v-model="model.deductExplains" placeholder="请输入扣费说明" :rows="4" />
        </a-form-model-item>
      </a-form-model>
    </a-spin>
  </j-modal>
</template>

<script>
import { getAction, httpAction } from '@/api/manage'
import moment from 'moment'

export default {
  name: 'xhdjVersionControlModal',
  data () {
    return {
      title: '操作',
      visible: false,
      amount: 0, //总金额
      model: {
        deductMoney: 0,
        deductExplains:null
      },
      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 }
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 }
      },

      confirmLoading: false,
      validatorRules: {},
      url: {
        //add: '/basics/xhdjVersionUpdates/add',
        edit: 'coach/xhdjCoachWithdrawal/initialPass',
        detail: 'coach/xhdjCoachWithdrawal/detail'
      }
    }
  },
  created () {

  },
  methods: {
    add () {
      //初始化默认值
      this.edit({})
    },
    edit (record) {
      this.model.id = record.id

      // 在Vue组件的方法中使用以下代码
      if (!record.deductMoney) {
        this.model.deductMoney = 0;
      } else {
        this.model.deductMoney = record.deductMoney;
      }
      this.model.deductExplains = record.deductExplains

      // getAction(this.url.detail, { id: res.id }).then(res => {
      //   if (res.code === 200) {
      //
      //   }
      // })


      this.amount = record.amount
      this.visible = true
    },
    close () {
      this.$emit('close')
      this.visible = false
      this.model = {}
      this.amount = 0
      this.$refs.form.clearValidate()
    },
    handleOk () {
      const that = this
      // 触发表单验证
      this.$refs.form.validate(valid => {
        if (valid) {
          that.confirmLoading = true
          let httpurl = ''
          let method = ''
          if (!this.model.id) {
            httpurl += this.url.add
            method = 'post'
          } else {
            httpurl += this.url.edit
            method = 'post'
          }
          httpAction(httpurl, this.model, method)
            .then(res => {
              if (res.success) {
                that.$message.success(res.message)
                that.$emit('ok')
                that.close()
              } else {
                that.$message.warning(res.message)
              }
            })
            .finally(() => {
              that.confirmLoading = false
              that.close()
            })
        } else {
          return false
        }
      })
    },
    handleCancel () {
      this.close()
    }
  }
}
</script>

<style lang="less" scoped></style>
